<?php

namespace plugin\admin\app\model;

use plugin\admin\app\model\Base;
use plugin\admin\app\model\traits\Listable;

/**
 * @property integer $id (主键)
 * @property integer $user_id 用户ID
 * @property string $company_logo 公司logo
 * @property string $company_name 公司名称
 * @property integer $count 灯库数量
 */
class UserDownloadLog extends Base
{

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'wa_user_download_logs';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';
    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;

    const TYPE_JOB = 1;

    const TYPE_PRODUCT = 2;

    public static function add($jobId, $type = self::TYPE_JOB)
    {
        return self::insertGetId([
            'job_id' => $jobId,
            'type' => $type,
            'user_id' => get_user_id(),
            'created_time' => date('Y-m-d H:i:s'),
        ]);
    }

    public static function hasRecord($jobId, $type = self::TYPE_JOB)
    {
        return self::where('job_id', $jobId)->where('type', $type)->where('user_id', get_user_id())->count() > 0;
    }
    
    
}
